//
//  YWMainViewController.swift
//  SwiftWeibo
//
//  Created by yawen on 16/2/28.
//  Copyright © 2016年 yawen. All rights reserved.
//

import UIKit

class YWMainViewController: UITabBarController, YWMainTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = YWMainTabBar()
        
        mainTabBar.composeDelegate = self
        
        setValue(mainTabBar, forKey: "tabBar")
        
        addChildViewController()
    }

    func mainTabBarComposeClick() {
        print("在 CZMainViewController 响应到了按钮的点击事件")
    }
    
    func addChildViewController() {
        
        //首页
        let homeVC = YWHomeViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home", selectImageName:"tabbar_home_highlighted")
        //发现
        let discoverVC = YWDiscoverViewController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover", selectImageName:"tabbar_discover_highlighted")
        // 占位的tabBar
        addChildViewController(UIViewController())
        
        //消息
        let messageVC = YWDiscoverViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center", selectImageName:"tabbar_message_center_highlighted")
        //我
        let profileVC = YWDiscoverViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile", selectImageName:"tabbar_profile_highlighted")
    }
    
    func addChildViewController(controller: UIViewController, title: String, imageName: String, selectImageName: String) {
        controller.title = title
        
        controller.tabBarItem.image = UIImage(named: imageName)
        
        // 设置图片不要渲染
        controller.tabBarItem.selectedImage = UIImage(named: selectImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置选中文字颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        // 添加为tabBar的子控制器,并且包装导航控制器
        addChildViewController(UINavigationController(rootViewController: controller))
        
    }

}
